package aex.action;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import aex.domain.ShowBox;
import aex.service.ShowBoxService;
import aex.util.CU;
import aex.util.PageBean;

import com.opensymphony.xwork2.ModelDriven;

@Controller("ShowBoxManagerAction")
@Scope("prototype")
public class ShowBoxManagerAction extends BaseActon implements ModelDriven<ShowBox> {

	private static final long serialVersionUID = 1L;

	@Resource(name = ShowBoxService.SERVICE_NAME)
	ShowBoxService sbService;
	
	ShowBox showBox = new ShowBox();

	public ShowBoxManagerAction() {
		CU.deBugPrintln("ShowBoxManagerAction 被创建");
	}

	@Override
	public ShowBox getModel() {
		return showBox;
	}


	public String showBoxList(){
		PageBean<ShowBox> pageBean = new PageBean<ShowBox>();
		PageBean.initPageBean(pageBean, request,"");
		pageBean = sbService.findAllBox(pageBean);
		request.setAttribute("pageBean", pageBean);
		return "showBoxList";
	}
	

	/**
	 * 删除单个栏目
	 * @return
	 */
	public String deleteShowBox(){
		int id=Integer.parseInt(request.getParameter("id"));
		sbService.deleteById(id);
		ajaxPrint("删除成功！");
		return null;
	}
	
	/**
	 * 删除多个栏目
	 * @return
	 */
	public String deleteShowBoxs(){
		String[] ids=request.getParameter("ids").split(",");
		for (int i = 0; i < ids.length; i++) {
			sbService.deleteById(ids[i]);
		}
		ajaxPrint("成功删除"+ids.length+"条数据！");
		return null;
	}
	
	
	
	public String addShowBox(){
		
		sbService.save(showBox);
		return CU.goMsgPage(request, "成功添加一个展位！", "ok", "manage/showBoxManager_showBoxList.do");
	}
	
	public String editorShowBox(){
		request.setAttribute("showBox", sbService.findByID(request.getParameter("id")));
		return "editorShowBox";
	}
	
	public String updateShowBox(){
		sbService.update(showBox);
		return CU.goMsgPage(request, "展柜已经更新！", "ok", "manage/showBoxManager_showBoxList.do");
	}
	
}
